<?php require admin_tpl('header')?>

<div class="tab">
	<ul>
		<li><a href="admin.php?mod=user"<?php echo $tabon['list']?>>用户列表</a></li>
		<li><a href="admin.php?mod=user&ac=add"<?php echo $tabon['add']?>>添加用户</a></li>
		<li><a href="admin.php?mod=user&ac=perm"<?php echo $tabon['perm']?>>权限设置</a></li>
	</ul>
</div>
<div class="main">

<?php if ( $ac == 'list' ) { ?>
	<div class="search">
		<form name="search" method="get" action="admin.php">
		<input type="hidden" name="mod" value="user" />
			<fieldset>
				<legend>用户查找</legend>
					关键字：
					<input type="text" name="keyword" size="15" value="<?php $keyword; ?>" />
					<input type="submit" name="s" class="button" value="开始查找" />
					<input type="button" class="button" value="显示所有" onclick="window.location.href='admin.php?mod=user'" />
			</fieldset>
		</form>
	</div>

	<form name="update" method="post" action="?mod=user">
		<table class="datalist" cellspacing="0" id="list">
			<tr>
				<th width="50" class="firstcol">选择</th>
				<th width="200">用户名</th>
				<th width="240">邮箱</th>
				<th width="80">审核</th>
				<th width="100">用户组</th>
				<th width="80">文章</th>
				<th width="80">评论</th>
				<th width="80">操作</th>
				<th>&nbsp;</th>
			</tr>
			<?php foreach ($result as $row) { ?>
			<tr id="row_<?php echo $row['id']?>" <?php echo $row['ischeck'] ? '' : 'class="highlight"'?>>
				<td align="center"><input type="checkbox" name="id[]" value="<?php echo $row['id']?>" <?php echo is_founder($row['id']) ? 'disabled="disabled"' : ''?> class="checkbox" /></td>
				<td><a href="?mod=user&ac=edit&id=<?php echo $row['id']?>"><?php echo $row['username']?></a> <?php echo is_founder($row['id']) ? '<span style="color:red">[创始人]</span>' : ''?></a></td>
				<td><a href="mailto:<?php echo $row['email']?>"><?php echo $row['email']?></a></td>
				<td align="center"><a href="?mod=user&ac=upstat&id=<?php echo $row['id']?>"><?php echo $row['ischeck'] ? '已通过' : '<span style="color:red">未通过</span>'?></a></td>
				<td align="center">
				<?php
					switch ( $row['group'] ) {
						case 'admin' :
							echo '<span style="color:red">管理员</span>'; break;
						case 'author' :
							echo '<span style="color:green">作者</span>'; break;
						case 'user' :
							echo '会员'; break;
					}
				?>
				</td>
				<td align="center"><a href="?mod=blog&uid=<?php echo $row['id']?>"><b style="color:green"><?php echo $row['posts']?></b></a></td>
				<td align="center"><a href="?mod=comment&uid=<?php echo $row['id']?>"><b style="color:orange"><?php echo $row['comments']?></b></a></td>
				<td align="center"><a href="?mod=user&ac=edit&id=<?php echo $row['id']?>">编辑</a></td>
				<td>&nbsp;</td>
			</tr>
			<?php } ?>
			<tr>
				<td align="center"><input type="checkbox" class="checkbox" value="1" id="checkall" name="chkall" onclick="check_all(this)" /></td>
				<td colspan="8"><label for="chkall">全选</label>
				<input type="radio" name="ac" value="update" id="update" class="radio" checked onclick="$('#span_move').hide()" /><label for="update">更新统计</label>
				<input type="radio" name="ac" value="delete" id="delete" class="radio" onclick="$('#span_move').hide()" /><label for="delete">删除用户</label>
				<input type="radio" name="ac" value="promote" id="promote" class="radio" onclick="$('#span_move').show()" /><label for="promote">更改用户组</label>
				<span id="span_move" style="display:none">
				<select name="group">
					<option value="user">会员</option>
					<option value="author">作者</option>
					<option value="admin">管理员</option>
				</select>
				</span>
				<input type="submit" class="submit" value="执行操作" /></td>

			</tr>
			<tr>
				<td colspan="10"><?php echo multipage()?></td>
			</tr>
		</table>
	</form>
<?php } elseif ( $ac == 'add' || $ac == 'edit' ) { ?>
<form name="user_add" method="post" action="?mod=user&ac=save" onsubmit="return check_form('username,email<?php if ($ac=='add') {echo ',password';}?>')">
<input type="hidden" name="dosubmit" value="yes" />
<input type="hidden" name="id" value="<?php echo $result['id']?>" />
<table cellspacing="0" class="sub">
	<tr>
		<td width="80" align="right">用户名：</td>
		<td><input type="text" name="username" id="username" class="input"<?php if ($ac=='edit'){echo ' disabled="disabled";';}?> size="20" value="<?php echo $result['username']?>" />
		</td>
	</tr>
	<tr>
		<td align="right">E-Mail：</td>
		<td><input type="text" name="email" id="email" class="input" size="40" value="<?php echo $result['email']?>" /></td>
	</tr>
	<tr>
		<td align="right">用户组：</td>
		<td>
		<select name="group">
			<option value="user">会员</option>
			<option value="author">作者</option>
			<option value="admin">管理员</option>
		</select>
		</td>
	</tr>
	<tr>
		<td align="right">密码：</td>
		<td><input type="text" name="password" id="password" class="input" size="22" />
		<?php if ( $ac == 'edit' ) { echo '<span>如果不想修改密码请留空</span>';}?>
		</td>
	</tr>
	<tr>
		<td align="right">Url：</td>
		<td><input type="text" name="url" id="url" class="input" size="40" value="<?php echo $result['url']?>" /></td>
	</tr>
	<tr>
		<td align="right">性别：</td>
		<td>
			<input type="radio" name="sex" id="sex" class="radio" value="0" <?php if ($result['sex']==0) {echo 'checked';}?>>保密
			<input type="radio" name="sex" id="sex" class="radio" value="1" <?php if ($result['sex']==1) {echo 'checked';}?>>男
			<input type="radio" name="sex" id="sex" class="radio" value="2" <?php if ($result['sex']==2) {echo 'checked';}?>>女
		</td>
	</tr>
	<?php do_action("user_{$ac}", $result);?>
	<tr class="bg2"><td></td><td><input type="submit" class="button" value="保存用户" /> <input type="button" class="button" onclick="history.back()" value="取消返回" /></td></tr>
</table>
</form>
<?php } elseif ( $ac == 'perm' ) { ?>
<form method="post" action="?mod=user&ac=perm">
<input type="hidden" name="dosubmit" value="yes" />
	<table class="sub panel" cellspacing="2">
		<tr><th class="title" colspan="2" style="cursor:pointer" onclick="$('#admin_perm').toggle()">管理员权限</th></tr>
		<tbody id="admin_perm">
		<tr>
			<td align="right" width="150">文章管理权限：</td>
			<td>
			<input type="checkbox" name="admin[blog][post]" id="admin_blog_post" value="1" class="checkbox" <?php checked('admin','blog','post')?> /> <label for="admin_blog_post">发布文章</label>
			<input type="checkbox" name="admin[blog][edit]" id="admin_blog_edit" value="1" class="checkbox" <?php checked('admin','blog','edit')?> /> <label for="admin_blog_edit">编辑文章</label>
			<input type="checkbox" name="admin[blog][check]" id="admin_blog_check" value="1" class="checkbox" <?php checked('admin','blog','check')?> /> <label for="admin_blog_check">审核文章</label>
			<input type="checkbox" name="admin[blog][del]" id="admin_blog_del" value="1" class="checkbox" <?php checked('admin','blog','del')?> /> <label for="admin_blog_del">删除文章</label>
			<input type="checkbox" name="admin[blog][move]" id="admin_blog_move" value="1" class="checkbox" <?php checked('admin','blog','move')?> /> <label for="admin_blog_move">移动文章</label>
			<input type="checkbox" name="admin[blog][addcate]" id="admin_blog_addcate" value="1" class="checkbox" <?php checked('admin','blog','addcate')?> /> <label for="admin_blog_addcate">添加分类</label>
			<input type="checkbox" name="admin[blog][editcate]" id="admin_blog_editcate" value="1" class="checkbox" <?php checked('admin','blog','editcate')?> /> <label for="admin_blog_editcate">编辑分类</label>
			<input type="checkbox" name="admin[blog][delcate]" id="admin_blog_delcate" value="1" class="checkbox" <?php checked('admin','blog','delcate')?> /> <label for="admin_blog_delcate">删除分类</label>
			</td>
		</tr>
		<tr>
			<td align="right">评论管理权限：</td>
			<td>
			<input type="checkbox" name="admin[comment][check]" id="admin_comment_check" value="1" class="checkbox" <?php checked('admin','comment','check')?> /> <label for="admin_comment_check">审核评论</label>
			<input type="checkbox" name="admin[comment][edit]" id="admin_comment_edit" value="1" class="checkbox" <?php checked('admin','comment','edit')?> /> <label for="admin_comment_edit">编辑评论</label>
			<input type="checkbox" name="admin[comment][reply]" id="admin_comment_reply" value="1" class="checkbox" <?php checked('admin','comment','reply')?> /> <label for="admin_comment_reply">回复评论</label>
			<input type="checkbox" name="admin[comment][del]" id="admin_comment_del" value="1" class="checkbox" <?php checked('admin','comment','del')?> /> <label for="admin_comment_del">删除评论</label>
			</td>
		</tr>
		<tr>
			<td align="right">链接管理权限：</td>
			<td>
			<input type="checkbox" name="admin[link][add]" id="admin_link_add" value="1" class="checkbox" <?php checked('admin','link','add')?> /> <label for="admin_link_add">添加链接</label>
			<input type="checkbox" name="admin[link][check]" id="admin_link_check" value="1" class="checkbox" <?php checked('admin','link','check')?> /> <label for="admin_link_check">审核链接</label>
			<input type="checkbox" name="admin[link][edit]" id="admin_link_edit" value="1" class="checkbox" <?php checked('admin','link','edit')?> /> <label for="admin_link_edit">编辑链接</label>
			<input type="checkbox" name="admin[link][del]" id="admin_link_del" value="1" class="checkbox" <?php checked('admin','link','del')?> /> <label for="admin_link_del">删除链接</label>
			<input type="checkbox" name="admin[link][cate]" id="admin_link_cate" value="1" class="checkbox" <?php checked('admin','link','cate')?> /> <label for="admin_link_cate">链接分类</label>
			</td>
		</tr>
		<tr>
			<td align="right">其它管理权限：</td>
			<td>
			<input type="checkbox" name="admin[attach][manage]" id="admin_attach_manage" value="1" class="checkbox" <?php checked('admin','attach','manage')?> /> <label for="admin_attach_manage">附件管理</label>
			<input type="checkbox" name="admin[tag][manage]" id="admin_tag_manage" value="1" class="checkbox" <?php checked('admin','tag','manage')?> /> <label for="admin_tag_manage">标签管理</label>
			</td>
		</tr>
		</tbody>

		<tr><th class="title" colspan="2" style="cursor:pointer" onclick="$('#author_perm').toggle()">作者权限</th></tr>
		<tbody id="author_perm">
		<tr>
			<td align="right" width="150">文章权限：</td>
			<td>
			<input type="checkbox" name="author[blog][post]" id="author_blog_post" value="1" class="checkbox" <?php checked('author','blog','post')?> /> <label for="author_blog_post">发布文章</label>
			<input type="checkbox" name="author[blog][needcheck]" id="author_blog_needcheck" value="1" class="checkbox" <?php checked('author','blog','needcheck')?> /> <label for="author_blog_needcheck">文章需要管理员审核</label>
			<input type="checkbox" name="author[blog][upload]" id="author_blog_upload" value="1" class="checkbox" <?php checked('author','blog','upload')?> /> <label for="author_blog_upload">允许上传附件</label>
			<input type="checkbox" name="author[blog][edit]" id="author_blog_edit" value="1" class="checkbox" <?php checked('author','blog','edit')?> /> <label for="author_blog_edit">编辑自己的文章</label>
			<input type="checkbox" name="author[blog][del]" id="author_blog_del" value="1" class="checkbox" <?php checked('author','blog','del')?> /> <label for="author_blog_del">删除自己的文章</label>
			</td>
		</tr>
		<tr>
			<td align="right" valign="top">前台权限：</td>
			<td>
			<input type="checkbox" name="author[comment][post]" id="author_comment_post" value="1" class="checkbox" <?php checked('author','comment','del')?> /> <label for="author_comment_post">发表评论</label>
			<input type="checkbox" name="author[comment][needcheck]" id="author_comment_needcheck" value="1" class="checkbox" <?php checked('author','comment','needcheck')?> /> <label for="author_comment_needcheck">评论需要审核</label>
			<input type="checkbox" name="author[comment][seccode]" id="author_comment_seccode" value="1" class="checkbox" <?php checked('author','comment','seccode')?> /> <label for="author_comment_seccode">评论需要验证码</label>
			<br />
			<label for="author_comment_timelimit">评论时间间隔</label> <input type="text" name="author[comment][timelimit]" size="5" id="author_comment_timelimit" value="<?php echo intval($permission['author']['comment']['timelimit'])?>" /> 秒<br />
			<label for="author_comment_maxchar">评论字数限制</label> <input type="text" name="author[comment][maxchar]" size="5" id="author_comment_maxchar" value="<?php echo  intval($permission['author']['comment']['maxchar'])?>" /> 字节
			</td>
		</tr>
		</tbody>

		<tr><th class="title" colspan="2" style="cursor:pointer" onclick="$('#user_perm').toggle()">会员权限</th></tr>
		<tbody id="user_perm">
		<tr>
			<td align="right" valign="top">前台权限：</td>
			<td>
			<input type="checkbox" name="user[comment][post]" id="user_comment_post" value="1" class="checkbox" <?php checked('user','comment','post')?> /> <label for="user_comment_post">发表评论</label>
			<input type="checkbox" name="user[comment][needcheck]" id="user_comment_needcheck" value="1" class="checkbox" <?php checked('user','comment','needcheck')?> /> <label for="user_comment_needcheck">评论需要审核</label>
			<input type="checkbox" name="user[comment][seccode]" id="user_comment_seccode" value="1" class="checkbox" <?php checked('user','comment','seccode')?> /> <label for="user_comment_seccode">评论需要验证码</label>
			<br />
			<label for="user_comment_timelimit">评论时间间隔</label> <input type="text" name="user[comment][timelimit]" size="5" id="user_comment_timelimit" value="<?php echo  intval($permission['user']['comment']['timelimit'])?>" /> 秒<br />
			<label for="user_comment_maxchar">评论字数限制</label> <input type="text" name="user[comment][maxchar]" size="5" id="user_comment_maxchar" value="<?php echo intval($permission['user']['comment']['maxchar'])?>" /> 字节
			</td>
		</tr>
		</tbody>

		<tr><th class="title" colspan="2" style="cursor:pointer" onclick="$('#guest_perm').toggle()">游客权限</th></tr>
		<tbody id="guest_perm">
		<tr>
			<td align="right" valign="top">前台权限：</td>
			<td>
			<input type="checkbox" name="guest[comment][post]" id="guest_comment_post" value="1" class="checkbox" <?php checked('guest','comment','post')?> /> <label for="guest_comment_post">发表评论</label>
			<input type="checkbox" name="guest[comment][needcheck]" id="guest_comment_needcheck" value="1" class="checkbox" <?php checked('guest','comment','needcheck')?> /> <label for="guest_comment_needcheck">评论需要审核</label>
			<input type="checkbox" name="guest[comment][seccode]" id="guest_comment_seccode" value="1" class="checkbox" <?php checked('guest','comment','seccode')?> /> <label for="guest_comment_seccode">评论需要验证码</label>
			<br />
			<label for="guest_comment_timelimit">评论时间间隔</label> <input type="text" name="guest[comment][timelimit]" size="5" id="guest_comment_timelimit" value="<?php echo  intval($permission['user']['comment']['timelimit'])?>" /> 秒<br />
			<label for="guest_comment_maxchar">评论字数限制</label> <input type="text" name="guest[comment][maxchar]" size="5" id="guest_comment_maxchar" value="<?php echo intval($permission['user']['comment']['maxchar'])?>" /> 字节
			</td>
		</tr>
		</tbody>
		<tr class="bg2">
			<td></td>
			<td><input type="submit" class="button" value="保存设置" /> <input type="button" class="button" onclick="history.back()" value="取消返回" /></td>
		</tr>
	</table>
</form>
<?php } ?>
</div>

<?php require admin_tpl('footer')?>